public class Stack {
    private  int[] elem;
    private int usedSize;


    private  static final int DEFAULT = 10;

    public Stack(){
        this.elem = new int[DEFAULT];
    }

    //入栈
    public void push(int val){
        if(isFull()){
            System.out.println("栈已经满了,不可以放元素了");
            return;
        }
        this.elem[this.usedSize] = val;
        this.usedSize++;
    }

    //出栈
    public int  pop(){
        if(isFull()){
            System.out.println("栈中没有元素,是空栈");
            return -1 ;
        }
        int val  = this.elem[this.usedSize - 1];
        this.usedSize--;
        return val;
    }

    //查看栈顶元素
    public int  peek(){
        return this.elem[this.usedSize - 1];
    }


    //判满
    public boolean isFull(){
        if(this.usedSize == this.elem.length){
            return  true;
        }
        return false;
    }


    //判空
    public boolean isEmpty(){
        if(this.usedSize == 0){
            return true;
        }
        return false;
    }
}
